{extend name="property/public/insidePageBase" /}
{block name="title"}物业详情{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form  layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">房间列表</li>
                    {if $propertyLogAuth}
                    <li>物业日志</li>
                    {/if}
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">

                        <!--房间列表 add-->
                        <script type="text/html" id="toolRoomListbar">
                            <div class="layui-btn-container">
                                {if $addAuth}<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="addRoom"> 添加房源</button>{/if}
                                {if $delAuth} <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>{/if}
                            </div>
                        </script>
                        <table class="layui-hide" id="propertyRoomList" lay-filter="propertyRoomList"></table>

                        <script type="text/html" id="tableRoomListBar">
                            <div class="layui-btn-group">
                                {if $editAuth} <a class="layui-btn layui-btn-sm  layui-btn-normal" lay-event="edit">编辑</a>{/if}
                                <a class="layui-btn layui-btn-sm" lay-event="details">详情</a>
                                {if $delAuth}<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</a>{/if}
                            </div>
                        </script>
                        <script type="text/html" id="room_name_tpl">
                            {{# if(d.status === 1) { }}
                            <span class="layui-badge layui-bg-cyan">空</span>
                            {{# } }}
                            {{# if(d.status === 2) { }}
                            <span class="layui-badge layui-bg-blue">租</span>
                            {{# if(d.pay_rent_status == 2) { }}
                            <span class="layui-badge">欠</span>
                            {{# } }}
                            {{# } }}
                            {{# if(d.full_room_name) { }}{{d.full_room_name}}  {{# } }}
                        </script>
                        <script type="text/html" id="contract_status_tpl">
                            {{# if(d.contract_status === 1) { }}
                            <span class="layui-badge layui-bg-orange">待审核</span>
                            {{# }else if (d.contract_status === 2) { }}
                            <span class="layui-badge layui-bg-blue">进行中</span>
                            {{# } else { }}
                            <span>---</span>
                            {{# } }}
                            {{# if(d.contract_end_date) { }}{{d.contract_end_date}} 到期{{# } }}
                            {{# if( d.status == 2) { }}
                            剩余<span style="color: red;"> {{ d.lave_days }} </span>天
                            {{# } }}
                        </script>
                        <!--房间列表 end-->
                    </div>
                    {if $propertyLogAuth}
                    <div class="layui-tab-item"> <!--物业日志 add-->
                        <table class="layui-hide" id="propertyLogList" lay-filter="propertyLogList"></table>
                        <script type="text/html" id="remark_tpl">
                            {{# if(d.remark) { }}{{d.remark}}{{# } }}
                        </script>
                    </div><!--物业日志 end-->
                    {/if}
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form', 'layer', 'table','upload'], function () {
        var form = layui.form,layer = layui.layer,  $ = layui.$, table = layui.table,upload = layui.upload;
        let propertyId = {$info['id']};
        <!-- 房间列表 add-->
        var tableRoomListId = 'propertyRoomList';
        table.render({
            elem: '#'+tableRoomListId,
            id:tableRoomListId,
            url: '{:url("propertyRoomBasicList")}?property_id='+propertyId,
            toolbar: '#toolRoomListbar',
            cols: [[
                {type: 'checkbox', fixed: 'left', rowspan: 2},
                {field: 'room_name', width: 328, title: '房间名称', templet:'#room_name_tpl'},
                {field: 'contract_status', width: 278, title: '租赁到期时间', templet:'#contract_status_tpl', sort: true},
                {field: 'room_size', width: 100, title: '面积', sort: true},
                {field: 'room_rent', width: 100, title: '租金/月', sort: true},
                {title: '操作', minWidth: 168, toolbar: '#tableRoomListBar', fixed:'right'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            height: 'full-150'
        });
        table.on('rowDouble('+tableRoomListId+')', function(obj){
            var data = obj.data;
            var url = '{:url("propertyRoomBasicDetail")}?room_id='+data.id;
            parent.layer.open({
                title: data.room_name +'  房间详情', type: 2, shade: 0.2, maxmin:true, shadeClose:true, move:false,area: ['1100px', '100%'],offset:  'rt', anim: 2, content: url , btn: false
            });
        });
        table.on('toolbar('+tableRoomListId+')', function (obj) {
            if (obj.event === 'addRoom') {  // 监听添加操作
                var url = '{:url("propertyRoomBasicAdd")}?property_id='+propertyId;
                var index = layer.open({title: '添加', type: 2, shade: 0.2,maxmin:true, area: ['650px', '80%'], content: url, btnAlign: 'c', btn: ['确定', '取消'], yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index], submit = layero.find('iframe').contents().find("#submitBtn");
                        iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                            var field = data.field; //获取提交的字段
                            var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                            $.post(url, field, function (res) {
                                layer.close(loadAdd);
                                if (res.code === 0) {
                                    table.reload(tableRoomListId); //数据刷新
                                    layer.close(index); //关闭弹层
                                    layer.msg(res.msg, {icon: 6, offset: '15px'});
                                } else {
                                    layer.msg(res.msg, {icon: 5, offset: '15px'});
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus(obj.config.id),data = checkStatus.data;
                var data = checkStatus.data, id = [];
                for (elem in data) {
                    id.push(data[elem].id);
                }
                if (id.length === 0) {
                    return layer.msg('请选择要删除的数据');
                }
                var url = '{:url("propertyRoomBasicDel")}';
                layer.confirm('删除后不可恢复！  是否确认? ', {icon: 3}, function () {
                    var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                    $.post(url, {ids: id}, function (res) {
                        layer.close(loadAdd);
                        if (res.code === 0) {
                            table.reload(tableRoomListId); //数据刷新
                            layer.msg(res.msg, {icon: 6, offset: '15px'});
                        } else {
                            layer.msg(res.msg, {icon: 5, offset: '15px'});
                        }
                    });
                });
            }
        });

        table.on('tool('+tableRoomListId+')', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var url = '{:url("propertyRoomBasicEdit")}?id='+data.id;
                var index = layer.open({
                    title: '编辑', type: 2,  shade: 0.2, maxmin:true, area: ['650px', '80%'],content: url, btnAlign: 'c', btn: ['确定', '取消'], yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index], submit = layero.find('iframe').contents().find("#submitBtn");
                        iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                            var field = data.field; //获取提交的字段
                            var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                            $.post(url, field, function (res) {
                                layer.close(loadAdd);
                                if (res.code === 0) {
                                    table.reload(tableRoomListId); //数据刷新
                                    layer.close(index); //关闭弹层
                                    layer.msg(res.msg, {icon: 6, offset: '15px'});
                                } else {
                                    layer.msg(res.msg, {icon: 5, offset: '15px'});
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'details') {
                let url = '{:url("propertyRoomBasicDetail")}?room_id='+data.id;
                var index = parent.layer.open({title: data.room_name +'  房屋详情', type: 2, shade: 0.2, maxmin:true, shadeClose:true, move:false,area: ['1100px', '100%'],offset:  'rt', anim: 2, content: url , btn:false });
                return false;
            } else if (obj.event === 'delete') {
                var url = '{:url("propertyRoomBasicDel")}';
                layer.confirm('删除后不可恢复！  是否确认? ', {icon: 3}, function () {
                    var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                    $.post(url, {ids: [data.id]}, function (res) {
                        layer.close(loadAdd);
                        if (res.code === 0) {
                            table.reload(tableRoomListId); //数据刷新
                            layer.msg(res.msg, {icon: 6, offset: '15px'});
                        } else {
                            layer.msg(res.msg, {icon: 5, offset: '15px'});
                        }
                    });
                });
            }
        });

        <!-- 房间列表 end-->
        <!-- 物业日志 add-->
        var tablePropertyLogListId = 'propertyLogList';
        table.render({
            elem: '#'+tablePropertyLogListId,
            id:tablePropertyLogListId,
            url: '{:url("propertyLogList")}?property_id='+propertyId,
            cols: [[
                {field: 'add_time', width: 168, title: '创建时间', sort: true},
                {field: 'username', width: 128, title: '执行用户',  sort: true},
                {field: 'remark', minWidth: 100, title: '备注说明', templet:'#remark_tpl'},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            height: 'full-150'
        });
        <!-- 物业日志 end-->
    });
</script>
{/block}